
import Vue from 'vue';
import Vuex from 'vuex';
import { request } from '../index';

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        shoppingCartData: {
            commodities: [],
            sumNumber: 0,
            sumPrice: 0,
            phoneNumber: ""
        }
    },
    mutations: {
        setShoppingCartData(state, payload) {
            state.shoppingCartData = payload;
        }
    },
    actions: {
        getShoppingCartData(context) {
            request.get("/shop/cartList").then(({ data }) =>
                context.commit("setShoppingCartData", {
                    commodities: data.list,
                    sumNumber: +data.num,
                    sumPrice: +data.all_price,
                    phoneNumber: data.phone,
                })
            );
        }
    }
});

